package top.wardyan.wmes.rfid.pub;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Path;

import top.wardyan.common.ctrl.BaseController;
import top.wardyan.wmes.rfid.kqa.dto.CmdExecuteResultDto;
import top.wardyan.wmes.rfid.kqa.dto.DeviceCmdListDto;
import top.wardyan.wmes.rfid.kqa.vo.BaseRequest;
import top.wardyan.wmes.rfid.kqa.vo.BaseResponse;

@Path("/cmd")
public class CmdController extends BaseController {

	private static final cn.hutool.log.Log log = cn.hutool.log.Log.get();
	/**
	@ActionKey("/cmd/report-cmd-result")
	public void reportCmdExecuteResult(){
	 //       log.info("上报指令执行结果，请求参数为：" + JSONObject.toJSON(request).toString());
	        BaseResponse<String> response = new BaseResponse<>();
	//	        CmdExecuteResultDto dto = request.getData();
	//	        String msg = cmdExecuteResultService.addCmdExecuteResult(dto);
	//	        if(!msg.equals("")){
	//	            response.setResult(500, msg);
	//	            return response;
	//	        }
	//	        response.setCode(200);
	    // return response;
	        
	        this.renderJson(response);
	}
	*/
	
	@SuppressWarnings("unchecked")
	@ActionKey("/cmd/get-station-cmd-list")
	public void getCmdList(){
	    BaseRequest<DeviceCmdListDto> params = this.getJson(BaseRequest.class);
		if(log.isInfoEnabled()) {
			log.info("获取指令,请求参数为:" + JSONObject.toJSONString(params));
		}
		BaseResponse<List<DeviceCmdListDto>> response = new BaseResponse<>();
		// response.setSuccess("OK");
		String s = "[{\"cmdContent\":\"string\",\"cmdLastExecuteTime\":\"2020/01/01 00:00:00\",\"cmdMakeTime\":\"2020/01/01 00:00:00\",\"cmdNumber\":0,\"cmdType\":0,\"deviceCmdID\":0,\"did\":0,\"gid\":0,\"retryTimes\":0,\"stationID\":0}]";
		 List<DeviceCmdListDto> dtoList = JSONArray.parseArray(s, DeviceCmdListDto.class);
		 response.setData(dtoList);
		this.renderJson(response);
	}
	
	/**
	 * 上报指令执行结果
	 */
	@SuppressWarnings("unchecked")
	@ActionKey("/cmd/report-cmd-result")
	public void reportCmdExecuteResult() {
		BaseRequest<CmdExecuteResultDto> params = this.getJson(BaseRequest.class);
		if(log.isInfoEnabled()) {
			log.info("上报指令执行结果,请求参数为:" + JSONObject.toJSONString(params));
		}
		BaseResponse<String> response = new BaseResponse<>();
		response.setSuccess("OK");
		this.renderJson(response);
	}
	
}
